package com.fr.lintcode;

import org.junit.Test;

public class Q1836 {
    /**
     * @param start:
     *            a point [x, y]
     * @param target:
     *            a point [x, y]
     * @return: return True or False
     */
    private boolean rs = false;

    public boolean ReachingPoints(int[] start, int[] target) {
        // write your code here
        if (start == null || target == null || start.length != 2 || target.length != 2) {
            return false;
        }
        int x = start[0];
        int y = start[1];
        search(x, y, target);
        return rs;
    }

    private void search(int x, int y, int[] target) {
        if (rs || x > target[0] || y > target[1]) {
            return;
        }
        if (x == target[0] && y == target[1]) {
            rs = true;
            return;
        }
        x = x + y;
        search(x, y, target);
        x = x - y;
        y = x + y;
        search(x, y, target);
        y = y - x;
    }

    @Test
    public void testA() {
        int start[] = {1, 2};
        int target[] = {5, 3};
        System.out.println(ReachingPoints(start, target));
    }

}
